

#include "crc8.h"


uint8_t crc8_compute(const uint8_t * pdata, uint16_t len, uint8_t init)
{
	uint8_t crc = init;
	
	while( len > 0 )
	{
		crc ^= (*pdata++); 
		for( uint32_t i = 0; i < 8; i ++ ){
			if( crc & 0x80 ){
				crc = (crc << 1) ^ 0x31; 
			}else{
				crc <<= 1;
			}
		}
		len --; 
	}
	return crc; 
}
